package com.cn.springcloudwechat.controller.articleAndMenu;


import com.cn.springcloudwechat.common.ajax.AjaxRes;
import com.cn.springcloudwechat.common.utils.base.Const;
import com.cn.springcloudwechat.model.articleAndMenu.YmMenuTag;
import com.cn.springcloudwechat.model.articleAndMenu.vo.YmMenuTagVo;
import com.cn.springcloudwechat.service.articleAndMenu.YmMenuTagService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 菜单相关Controller
 * @program: YmMenuTagController
 * @author: Administrator
 * @create: 2018-07-17 16:39
 */
@RestController
@RequestMapping("/web/menu/")
public class YmMenuTagControllerWeb {

    @Autowired
    YmMenuTagService ymMenuTagService;

    /**
     * 添加菜单
     *
     * @param ajaxRes
     * @param record
     * @return
     */
    @RequestMapping(value = "insertYmMenuTag", method = RequestMethod.POST)
    public AjaxRes insertYmMenuTag(AjaxRes ajaxRes, YmMenuTag record) {
        ymMenuTagService.insertYmMenuTag(record);
        ajaxRes.setSucceedMsg(Const.SAVE_SUCCEED);
        return ajaxRes;
    }

    /**
     * 获取单个菜单
     *
     * @param ajaxRes
     * @param menuTagId
     * @return
     */
    @RequestMapping(value = "selectYmMenuTag", method = RequestMethod.GET)
    public AjaxRes selectYmMenuTag(AjaxRes ajaxRes, @RequestParam Long menuTagId) {
        YmMenuTag record = ymMenuTagService.getOneYmMenuTag(menuTagId);
        ajaxRes.setSucceed(record);
        return ajaxRes;
    }

    /**
     * 更新菜单
     *
     * @param ajaxRes
     * @param record
     * @return
     */
    @RequestMapping(value = "updateYmMenuTag", method = RequestMethod.POST)
    public AjaxRes updateYmMenuTag(AjaxRes ajaxRes, YmMenuTag record) {
        ymMenuTagService.updateYmMenuTag(record);
        ajaxRes.setSucceedMsg(Const.UPDATE_SUCCEED);
        return ajaxRes;
    }

    /**
     * 获取所有菜单数据
     *
     * @param ajaxRes
     * @param record
     * @return
     */
    @RequestMapping(value = "getAllMenuTag", method = RequestMethod.GET)
    public AjaxRes getAllMenuTag(AjaxRes ajaxRes, YmMenuTag record) {
        List<YmMenuTag> ymMenuTags = ymMenuTagService.getAllMenuTag(record);
        ajaxRes.setSucceed(ymMenuTags);
        return ajaxRes;
    }

    /**
     * 获取初始菜单数据
     *
     * @param ajaxRes
     * @return
     */
    @RequestMapping(value = "getStairMenu", method = RequestMethod.GET)
    public AjaxRes getStairMenu(AjaxRes ajaxRes) {
        List<YmMenuTag> ymMenuTags = ymMenuTagService.getStairMenu();
        ajaxRes.setSucceed(ymMenuTags);
        return ajaxRes;
    }

    /**
     * 获取菜单树
     *
     * @param ajaxRes
     * @param menuTagId
     * @return
     */
    @RequestMapping(value = "getMenuTree", method = RequestMethod.GET)
    public AjaxRes getMenuTree(AjaxRes ajaxRes, Long menuTagId) {
        List<YmMenuTagVo> ymMenuTagVos = ymMenuTagService.getMenuTree(menuTagId);
        ajaxRes.setSucceed(ymMenuTagVos);
        return ajaxRes;
    }


}
